package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class News extends BaseDomain{

    public static final Integer STATE_STOP = 0;   // 禁用
    public static final Integer STATE_PUBLIC = 1;     // 发布

    private Integer sequence;

    private String title;

    private String subTitle;

    private String coverUrl;

    private Integer state = STATE_PUBLIC;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;
    //浏览数量
    private Integer browseNum;
    //点赞数量
    private Integer likeNum;
    //收藏数量
    private Integer collectionNum;

    //点评内容
    private NewsContent newsContent;

    //该文章评论的次数
    private Integer commentNum;
    //关联收藏者的id
    private User user;

    public String getStateName() {
        String temp = "";
        if (state == STATE_STOP) {
            temp = "禁用";
        }else if(state == STATE_PUBLIC){
            temp = "发布";
        }
        return temp;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        map.put("title", title);
        map.put("subTitle", subTitle);
        map.put("coverUrl", coverUrl);
        map.put("state", state);
        map.put("sequence", sequence);
        map.put("collectionNum", collectionNum);
        map.put("likeNum", likeNum);
        map.put("browseNum", browseNum);
        if (releaseTime!=null){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            map.put("releaseTime", sdf.format(releaseTime));
        }
        return JSON.toJSONString(map);
    }
}